package com.assist.beans;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import com.assist.model.User;
import com.assist.service.IUserService;
import com.assist.service.impl.UserServiceImpl;


@ManagedBean(name = "registerUserBean")
@RequestScoped
public class RegisterUserBean implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	private String firstName;
	private String lastName;
	private String userName;
	private String gender;
	private String mobile;
	private String birthdate;
	private String password;
	private String passwordConfirmation;
	
	public String getFirstName() {
		return firstName;
	}



	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}



	public String getLastName() {
		return lastName;
	}



	public void setLastName(String lastName) {
		this.lastName = lastName;
	}



	public String getUserName() {
		return userName;
	}



	public void setUserName(String userName) {
		this.userName = userName;
	}



	public String getGender() {
		return gender;
	}



	public void setGender(String gender) {
		this.gender = gender;
	}



	public String getMobile() {
		return mobile;
	}



	public void setMobile(String mobile) {
		this.mobile = mobile;
	}





	public String getPassword() {
		return password;
	}



	public void setPassword(String password) {
		this.password = password;
	}



	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}



	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}

	public String getBirthdate() {
		return birthdate;
	}



	public void setBirthdate(String birthdate) {
		this.birthdate = birthdate;
	}

	
	public RegisterUserBean(){}
	


	public void registerUser(ActionEvent e) {
		System.out.println("Register clicked!");
	
		IUserService userService = new UserServiceImpl();
		User user = new User(firstName,lastName,userName,gender,mobile,birthdate,password,passwordConfirmation);
		boolean result=userService.saveOrUpdateUser(user);
		if (result) {
			try {
				FacesContext.getCurrentInstance().getExternalContext().redirect("login.xhtml");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
			
	}

	

}
